<template>
	<view>
		<view class="hedaerTop" 
			:class="isbg == '1' ? '' : 'whie' " 
			:style="'height:' + navHeight + 'px;' + computedStyle"
			>
			<!-- <view class="anqq"></view> -->
			<view class=""></view>
			<view class="top-com">
				<slot name="left">
					<image @click="go"
							v-if="is_back"
						   :src="baseUrl + 
						   '/static/wximages/arrow-pointing-to-righi'+ 
						   (isbg == '1' ? '' : '2') +'.png'" 
						   >
					</image>
				</slot>
				<view class="title">
					<slot name="title">
						<text>{{title}}</text>
					</slot>
				</view>
				
			</view>
		</view>
		
		<view class="stickys" v-if="stickys" :style="'height:'+navHeight+'px'"></view>
	
	</view>
	
</template>

<script>
	export default {
		data() {
			return {
				baseUrl: this.$baseUrl,
				navHeight: 0
			}
		},
		props: {
			title: {
				type: String,
				default () {
					return '';
				}
			},
			isbg: {
				type: String,
				default () {
					return '1';
				}
			},
			stickys: {
				type: Boolean,
				default () {
					return false;
				}
			},
			is_back: {
				type: Boolean,
				default () {
					return true;
				}
			},
			barStyle:{
				type:[Object,Array],
				default:()=>({})
			}
			
		},
		computed:{
			computedStyle(){
				let str = ''
				for(let key in this.barStyle){
					str+=`${key}:${this.barStyle[key]};`
				}
				return str
			}
		},
		created() {
			// 状态栏高度
			let statusBarHeight = uni.getSystemInfoSync().statusBarHeight
		 
			// #ifdef MP-WEIXIN
			// 获取微信胶囊的位置信息 width,height,top,right,left,bottom
			const custom = wx.getMenuButtonBoundingClientRect()
			// console.log(custom)
		 
			// 导航栏高度(标题栏高度) = 胶囊高度 + (顶部距离 - 状态栏高度) * 2
			let navigationBarHeight = custom.height + (custom.top - statusBarHeight) * 2
			// console.log("导航栏高度："+this.globalData.navigationBarHeight)
		 
			// 总体高度 = 状态栏高度 + 导航栏高度
			let navHeight = navigationBarHeight + statusBarHeight
		 
			// #endif
			
			// #ifdef H5
			
			let navHeight = 45;
			// #endif
			this.navHeight = navHeight;

		},
		methods: {
			jump(url) {
				uni.switchTab({
					url: url
				})
			},
			go() {
				var routes = getCurrentPages();
				if (routes.length > 1) {
					uni.navigateBack();
				} else {
					uni.switchTab({
						url: '/pages/card/index'
					})
				}
			}
		}
	}
</script>

<style scoped>
	
	.hedaerTop {
		position: fixed;
		left: 0;
		top: 0;
		right: 0;
		
		display: flex;
		justify-content: space-between;
		flex-direction: column;
		background-color: initial;
		z-index: 999;
	}
	.hedaerTop.whie {
		background-color: #fff;
	}
	.stickys {
		height: calc(60rpx + var(--status-bar-height));
	}
	.hedaerTop .anqq {
		width: 100%;
		height: var(--status-bar-height);
	}
	.hedaerTop .top-com {
		position: relative;
		display: flex;
		align-items: center;
		height: 80rpx;
		/* justify-content: center; */
		/* height: 60rpx; */
		padding: 0;
		box-sizing: border-box;
		color: #fff;
		font-size: 36rpx;
	}
	.hedaerTop.whie .top-com {
		color: #333;
	}
	
	.hedaerTop .top-com image {
		width: 80rpx;
		height: 80rpx;
		padding: 20rpx;
		/* margin-right: 20rpx; */
		box-sizing: border-box;
	}
	
	.hedaerTop .top-com .title {
		position: absolute;
		left: 50%;
		transform: translateX(-50%);
		font-size: 28rpx;
	}
</style>